#include "progressthread.h" 
#include <qmessagebox.h>

ProgressThread::ProgressThread(QStringList& files, MainWindow *parent):
		_files(files), canceled(false)
{
	_parent = parent;
}

void ProgressThread::cancel() {
	canceled = true;
}

void ProgressThread::showError(QString error) {
	QMetaObject::invokeMethod((QWidget*)_parent, "showError", Qt::BlockingQueuedConnection, Q_ARG(QString, error));
}

void ProgressThread::run() {
	for (int i = 0; i < _files.count(); i++) {
		if (!job(_files[i])) {
			emit jobAborted();
			break;
		}
		emit jobFinished(i == _files.count() - 1 ? "" : _files[i]);
		if (canceled)
			break;
	}
	emit threadFinished();
}